package com.itheima.reggie.dao;

import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.dto.SetmealDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealDao {

    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Integer findCountByCategoryId(Long categoryId);

    @Insert("insert into setmeal values(null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void save(SetmealDto setmealDto);

    List<Setmeal> findByName(@Param("name") String name);

    // 根据套餐的id查询在售数量
    int findCountByIds(@Param("ids") List<Long> ids);

    void deleteByIds(@Param("ids") List<Long> ids);

    @Select("select * from setmeal where category_id = #{categoryId} and status = #{status}")
    List<Setmeal> list(@Param("categoryId") Long categoryId, @Param("status") Integer status);
}
